<template>
    <article v-if="props.modelValue?.length" class="zw-group-render-list">
        <div v-for="item in props.modelValue" :key="item.id" class="zw-group-render-item">
            <div class="zw-group-render-info">
                <div class="remove" @click="handleRemove(item)">
                    <el-icon size="16px" color="#1890ff">
                        <CircleCloseFilled />
                    </el-icon>
                </div>
                <div class="group_avatar">
                    <ZWGroupAvatar :avatars="item.avatars" />
                </div>
                <div class="group_info">
                    <div class="group_info_name">
                        <span>{{ item.name }}</span>
                        <span v-if="item.isDelete" class="delete_group" >已解散</span>
                    </div>
                    <div class="group_info_number">{{ item.count || '0' }} 人</div>
                    <div class="group_info_owner">群主: {{ item.ownerName }}</div>
                </div>
            </div>
        </div>
    </article>
</template>

<script setup lang="ts">
import { computed, ref } from "vue"
import { CircleCloseFilled, ArrowDownBold } from '@element-plus/icons-vue'
import ZWGroupAvatar from './ZWGroupAvatar.vue'

interface Props {
    modelValue: any[],
}
const props = withDefaults(defineProps<Props>(), {
    modelValue: () => []
})
const emit = defineEmits(['update:modelValue'])

const handleRemove = (item) => {
    emit('update:modelValue', props.modelValue.filter(rowItem => rowItem.id !== item.id))
}

</script>

<style lang="scss" scoped>
.zw-group-render-list {
    margin-top: 12px;
    display: grid;
    gap: 8px;
    grid-template-columns: repeat(4, 1fr);
    max-height: 230px;
    overflow-y: auto;
    padding-right: 16px;

    .zw-group-render-item {
        padding: 8px 8px 0 0;

        .zw-group-render-info {
            position: relative;
            box-sizing: border-box;
            cursor: pointer;
            // display: grid;
            // grid-template-columns: 46px 1fr;
            display: flex;

            padding: 10px;
            border: 1px solid #ccc;
        }


        .remove {
            position: absolute;
            right: -16px;
            top: 2px;
            transform: translate(-50%, -50%);
        }

        .group_avatar {
            flex: 0 0 46px;
            width: 46px;
            height: 46px;

            img {
                border-radius: 6px;
                width: 100%;
                height: 100%;
            }
        }

        .group_info {
            flex: 1;
            line-height: normal;
            margin-left: 8px;
            font-size: 12px;
            font-family: var(--text-family-l);
            color: var(--title-color);
            max-width: 140px;

            > div {
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
            }

            .group_info_name {
                display: flex;
                justify-content: space-between;
                span:first-child {
                    min-width: 0;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    white-space: nowrap;
                }
                .delete_group {
                    color: #F56C6C;
                }
            }

            .group_info_number {
                font-size: 12px;
                color: var(--main-color);
            }

            .group_info_owner {
                font-size: 12px;
                color: var(--assist-color);
            }
        }
    }
}

.zw-group-render-footer {
    display: flex;
    justify-content: space-between;
    color: var(--assist-color);

    .footer_show_all {
        cursor: pointer;
        vertical-align: middle;

        .el-icon {
            margin-left: 6px;
        }
    }
}

.group_count {
    color: var(--main-color);
}
</style>
